//Item集合
import 'dart:convert';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:village_android/config/contants.dart';
import 'package:village_android/utils/common_utils.dart';

class GirdCollection extends StatelessWidget {

  String type = "";
  GirdCollection({this.type});

  //独立Item
  Widget _girdInkWell(BuildContext context, item) {
    return InkWell(
      onTap: () {
         CommonUtils.pushPage(context, item);
      },
      child: Column(
        children: <Widget>[
//          Image(
//            image: new CachedNetworkImageProvider(kImageHost + item["icon"] + '.png'),
//            width: ScreenUtil().setWidth(50),
//            height: ScreenUtil().setHeight(55),
//            fit: BoxFit.contain,),

//          getCacheImage(kImageHost + item["icon"] + '.png'),
          Image.network(kImageHost + item["icon"] + '.png',
            width: 30,
            height: 30,
            fit: BoxFit.contain,),
          Container(
            padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
            child: Text(item["title"],
              maxLines: 2,
              textAlign: TextAlign.center,
              style: TextStyle(
                  fontSize: ScreenUtil().setSp(22)
              ),),
          )

        ],
      ),
    );
  }


  @override
  Widget build(BuildContext context) {

    return new FutureBuilder(
        future: DefaultAssetBundle.of(context).loadString("assets/menu.json"),
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            Map data = json.decode(snapshot.data.toString());
            List items = data[type];
            return Container(
                height: 140 ,
                padding: EdgeInsets.all(3.0),
                child: GridView.count(
                  physics: new NeverScrollableScrollPhysics(),
                  crossAxisCount: 5,
                  padding: EdgeInsets.all(3.0),
                  children: items.map((item) {
                    return _girdInkWell(context, item);
                  }).toList(),
                ));
          }
          return new CircularProgressIndicator();
        });
  }
}